﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="jquery.min.js"></script>
</head>
<body>
    <div><span style="color:red;">111</span></div>
    <script>
        $.ajax({
            type: "post",
            url: "http://localhost:5000/api/JWTGet/Test2?passWord=123456",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify({ userName: "admin" }),
            dataType: "json",
            success: function (data) {
                JWTCheck(data);
                console.log(data);
            },
            error: function (e) {
                console.log(e);
            }
        });


        function JWTCheck(data) {
            localStorage["Token"] = data.type + " " + data.access_token;
            $.ajax({
                type: "get",
                url: "http://localhost:5000/api/JWTCheck/CheckJWT?passWord=123456",
                //contentType: 'application/json;charset=utf-8',
                beforeSend: function (xhr) {
                    //设置header
                    xhr.setRequestHeader("Authorization", window.localStorage["Token"]);
                    xhr.setRequestHeader("Content-Type", 'application/json;charset=utf-8');
                },
                dataType: "json",
                success: function (data) {
                    console.log(data);
                },
                error: function (e) {
                    console.log(e);
                }
            });
        }

    </script>
</body>
</html>